﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MatTroi.vn.Models
{
    public class HomeViewModel
    {
        Entities db = new Entities();
        // DANH MUC NHO
        public List<tbl_Website> GetWebDanhMuc(int Id)
        {
            var dmWeb = db.tbl_WebDM.Where(e => e.tbl_DanhMuc.ID_DanhMucCha == Id /*&& e.tbl_DanhMuc.IsHot == false*/ /*&& e.tbl_Website.IsHot== true*/).OrderByDescending(e => e.tbl_Website.XepHang).Take(12).ToList();
            List<tbl_Website> Web = new List<tbl_Website>();
            foreach (var item in dmWeb)
            {
                Web.Add(item.tbl_Website);
            }
            return Web;
        }
        // DANH MUC LON
        public List<tbl_Website> GetWebDanhMucLon(int Id)
        {
            var dmWeb = db.tbl_WebDM.Where(e => e.tbl_DanhMuc.ID_DanhMucCha == Id && e.tbl_DanhMuc.IsHot == false && e.tbl_Website.IsHot == true).OrderByDescending(e => e.tbl_Website.XepHang).Take(14).ToList();
            List<tbl_Website> Web = new List<tbl_Website>();
            foreach (var item in dmWeb)
            {
                Web.Add(item.tbl_Website);
            }
            return Web;
        }   
        public List<tbl_DanhMuc> GetDanhMuc()
        {
            var dm = db.tbl_DanhMuc.Where(e => e.ID_DanhMucCha == null && e.IsHot == true).OrderBy(e=>e.ViTri).ToList();
            return dm;
        }
        public List<tbl_Website> getWebNoiBat()
        {
            var WebNoiBat= db.tbl_Website.Where(e=>e.XepHang>=2).OrderByDescending(e=>e.XepHang).Take(30).ToList();
            return WebNoiBat;

        }
        public List<tbl_DanhMuc> getTheLoai(int Id)
        {
            var TheLoai = db.tbl_DanhMuc.Where(e => e.ID_DanhMucCha == Id && e.IsHot == true).ToList();
            return TheLoai;
        }
        public List<tbl_Website> getChiTietTheLoai(int Id)
        {
            var dmWeb = db.tbl_WebDM.Where(e => e.tbl_DanhMuc.ID_DanhMucCha==Id  && e.tbl_Website.IsHot == true && e.tbl_DanhMuc.IsHot==true ).OrderByDescending(e => e.tbl_Website.XepHang).Take(20).ToList();
            List<tbl_Website> Web = new List<tbl_Website>();
            foreach (var item in dmWeb)
            {
                Web.Add(item.tbl_Website);
            }
            return Web;
        }
        public bool KiemTraGioiThieu(int Id)
        {
           
            if (db.tbl_DanhMuc.Where(e => e.ID_DanhMucCha == Id && e.IsHot == true).Count() != 0) return true;
            else return false;
        }
        // Danh muc an
        public List<tbl_DanhMuc> GetDanhMucAn()
        {
            var dm = db.tbl_DanhMuc.Where(e => e.ID_DanhMucCha == null && e.IsHot == false).Take(6).ToList();
            return dm;
        }
        public List<tbl_Website> GetWebDanhMucAn(int Id)
        {
            var dmWeb = db.tbl_WebDM.Where(e => e.tbl_DanhMuc.ID_DanhMucCha == Id && e.tbl_DanhMuc.IsHot == false).OrderByDescending(e => e.tbl_Website.XepHang).Take(12).ToList();
            List<tbl_Website> Web = new List<tbl_Website>();
            foreach (var item in dmWeb)
            {
                Web.Add(item.tbl_Website);
            }
            return Web;
        }
    }
}